const App = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        showShade: false,
        page: 1,
        hasMore: true,
        size: 10,
        list:[]
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(options)
        this.setData(options)
    },

    onPullDownRefresh() {
        //请求数据更新
        console.log('refresh')
        this.setData({page: 1, hasMore: true, list: []})
        this.loadAgentSales();
    },
    onReachBottom(event) {
        //请求更多数据
        console.log('load more')
        this.setData({
            page: this.data.page + 1
        });
        this.loadAgentSales();
    },

    onChange(e) {
        console.log(e.detail)
        this.setData(e.detail)
        this.setData({showShade: false})
        this.onPullDownRefresh();
    },
    onConditionToggle(e) {
        console.log(e.detail.conditionSearch)
        this.setData({showShade: e.detail.conditionSearch})
    },
    loadAgentSales() {
        if (!this.data.hasMore) {
            return;
        }
        let _this = this
        let data = {
            searchType: this.data.searchType,
            years: this.data.years,
            months: this.data.months,
            seasonIndex: this.data.seasonIndex,
            monthIndex: this.data.monthIndex,
            yearIndex: this.data.yearIndex,
            userId: this.data.userId,
            page: _this.data.page,
            size: _this.data.size
        }
        App._post_form('index/agent_sales', data, function (result) {
            console.log("加载数据成功")
            if (result.data.list.length < _this.data.size) {
                console.log("没有更多数据了")
                _this.setData({
                    'hasMore': false,
                    'isLoading': false,
                });
            }
            let rows = _this.data.list.concat(result.data.list);
            _this.setData({
                page: _this.data.page + 1,
                list: rows,
                'isLoading': false,
                'user':result.data.user,
                'totals':result.data.totals,
            })
        })
    },
    navigateToOrderDetail(e) {
        let orderId = e.currentTarget.dataset.order_id;
        wx.navigateTo({
            url: '/pages/agent/order/detail?order_id=' + orderId,
        });
    }

});